﻿using Cms.Core.Infrastructure.Dependency;
using Cms.Core.Infrastructure.Extension;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Cms.Core.Infrastructure.Extensions
{
   public static class ServiceExtensions
    {

        /// <summary>
        /// 自动注入指定服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddCustomServices(this IServiceCollection services)
        {
            services.NotNull(nameof(services));
            services = new AppServiceAdder().AddServices(services);
            SetApplicationServiceProvider(services);
            return services;
        }


        /// <summary>
        /// 设置应用程序服务提供商
        /// </summary>
        /// <param name="services"></param>
        private static void SetApplicationServiceProvider(this IServiceCollection services)
        {


            var serviceProvider = services.BuildServiceProvider();
            ServiceLocator.Instance.SetApplicationServiceProvider(serviceProvider);
        }
    }
}
